package chapter03;

/**
 * ClassName: Java04_Exception
 * Package: chapter03
 * DESCRIPTION:
 *
 * @Author 程翎钥
 * @Create 2024/4/14 16:35
 * @Version 1.0
 */
public class Java04_Exception {
    public static void main(String[] args) {

        // TODO 异常
        //3. 索引越界 :java.lang.ArrayIndexOutOfBoundsException
        String[] names = new String[3];
        names[0] = "z";
        names[1] = "l";
        names[2] = "w";
        if (names.length == 4) {
            names[3] = "y";
        }

        //4. 字符串索引越界 : java.lang.StringIndexOutOfBoundsException
        String s = "abc";
        //System.out.println(s.charAt(3));
        System.out.println(s.substring(3));//截取字符串时，大于其长度才会报错

    }
}
